package com.zhang.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhang.goods.entity.SkuImags;
import com.zhang.goods.mapper.SkuImagsMapper;
import com.zhang.goods.service.ISkuImagsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * sku图片信息表 服务实现类
 * </p>
 *
 * @author 创世神
 * @since 2023-10-05
 */
@Service
@Slf4j
public class SkuImagsServiceImpl extends ServiceImpl<SkuImagsMapper, SkuImags> implements ISkuImagsService {

    @Override
    public List<SkuImags> getBySkuId(Long skuId) {
        QueryWrapper<SkuImags> wrapper = new QueryWrapper<>();
        wrapper.eq("sku_id", skuId);
        List<SkuImags> list = list(wrapper);
        return list;
    }

    @Override
    public Long getDefalutImgIdBySkuId(Long skuId) {
        LambdaQueryWrapper<SkuImags> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SkuImags::getSkuId, skuId);
        wrapper.eq(SkuImags::getIsDefault, 0);
        SkuImags one = getOne(wrapper);
        if (one != null) {
            return one.getImgId();
        }

        log.error("这个sku的图片没找到哦，他的skuid是:{}",skuId);
        return null;
    }
}
